﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MySoftWare.Component.Tools
{
    /// <summary>
    /// added by lqm 2013.06.01
    /// </summary>
    public static class MD5Security
    {
        /// <summary>
        /// 对密码进行MD5加密
        /// </summary>
        /// <param name="sourceString"></param>
        /// <returns></returns>
        public static string Encode(this string sourceString)
        {
            ///取得sourceString的MD5 HashCode，再转换为base64 code，共24个字符。
            char[] chars = sourceString.ToCharArray();
            int count = chars.Length;
            byte[] bytes = new byte[count];
            for (int i = 0; i < count; i++)
            {
                bytes[i] = (byte)chars[i];
            }
            System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
            md5.ComputeHash(bytes);
            return Convert.ToBase64String(md5.Hash);
        }
    }
}
